﻿using System;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Sustainalytics.Controversies.Service.BlInvoker;
using Sustainalytics.Utils.WebApi.ErrorCodes;
using System.Web.Http.Cors;

namespace Sustainalytics.Controversies.Service.Controllers
{
    //TODO add claims and universe checker
    [EnableCors(origins: "*", headers: "*", methods: "*")]
    [RoutePrefix("api/v1/company")]
    public class ControversyIndicatorController : ApiController
    {
        private readonly IServiceBlInvoker _blInvoker;

        public ControversyIndicatorController(IServiceBlInvoker blInvoker)
        {
            _blInvoker = blInvoker;
        }

        // this one 
        [Route("{companyId}/controversyIndicator/{controversyIndicatorId}")]
        public HttpResponseMessage Get(Guid companyId, Guid controversyIndicatorId, [FromUri] bool qualitativeperformance)
        {
            try
            {// todo to implement and simple list, return - where qualitativeperformance = fasle

                if (!qualitativeperformance)
                    return Request.CreateResponse(HttpStatusCode.NotImplemented,
                        "Qualitativeperformance indicator in this request must be true");
                return Request.CreateResponse(HttpStatusCode.OK, _blInvoker.GetCompanyQualitativePerformance(companyId));
            }
            catch (Exception)
            {
                return Request.CreateResponse(HttpStatusCode.InternalServerError,
                    new { ErrorStatusCode = WebAPIGeneralErrorCodes.UnhandledException });
            }
        }

        [Route("{companyId}/controversyIndicator")]
        public HttpResponseMessage Get(Guid companyId, [FromUri]string theme)
        {
            try
            {
                return Request.CreateResponse(HttpStatusCode.OK,
                    _blInvoker.GetControversyIndicators(companyId, theme));
            }
            
            catch (Exception )
            {
                return Request.CreateResponse(HttpStatusCode.InternalServerError,
                    new { ErrorStatusCode = WebAPIGeneralErrorCodes.UnhandledException });
            }
        }
    }
}
